#pragma once

// TODO implement correctly... so that sprites don't end up loading duplicate images

class SpriteSystem
{
private:
	/** [surface#][ptr] */
	SDL_Surface ** m_surfaces;
	/** names of the surfaces */
	char ** m_surfaceNames;
	/** */
	int m_numSurfaces;
public:
	void loadImages(char ** a_imageFiles, const int & a_numImageFiles)
	{
		m_numSurfaces = a_numImageFiles;
		m_surfaces = new SDL_Surface * [m_numSurfaces];
		m_surfaceNames = new char * [m_numSurfaces];
		for(int f = 0; f < m_numSurfaces; ++f)
		{
			int sizeInBytes = strlen(a_imageFiles[f])+1;
			m_surfaceNames[f] = new char[sizeInBytes];
			strcpy_s(m_surfaceNames[f], sizeInBytes, a_imageFiles[f]);
			SDL_Surface *temp = SDL_LoadBMP(m_surfaceNames[f]);
			m_surfaces[f] = SDL_DisplayFormat(temp);
		    SDL_FreeSurface(temp);
		}
	}
	void release()
	{
		if(m_numSurfaces)
		{
			for(int f = 0; f < m_numSurfaces; ++f)
			{
				SDL_FreeSurface(m_surfaces[f]);
				delete [] m_surfaceNames[f];
			}
			delete [] m_surfaces;
			delete [] m_surfaceNames;
			m_surfaces = 0;
			m_surfaceNames = 0;
			m_numSurfaces = 0;
		}
	}
};
